package com.sticktogether;

import com.sticktogether.multiphotoselect.MultiPhotoSelectActivity;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

public class LogoutActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_logout);
	}
	
	@Override
	protected void onResume() {
    	SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    	if(	sharedPref.getBoolean("tracking_enable", true) && 
    		(((LocationManager) getSystemService( LOCATION_SERVICE )).isProviderEnabled( LocationManager.GPS_PROVIDER ) ||
    		((LocationManager) getSystemService( LOCATION_SERVICE )).isProviderEnabled( LocationManager.NETWORK_PROVIDER ))) {
    		Intent intent = new Intent(this,MapViewActivity.class);
        	this.startActivity(intent);
    	}
		super.onResume();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.menu, menu);
		return true;
	}
	
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
	    // Handle item selection
    	Intent i = new Intent();
	    switch (item.getItemId()) {
	    	// Settings button was pressed
	        case R.id.menu_settings:
	    		i.setClass(this, SettingsActivity.class);
	    		startActivity(i);
	            return true;
	        case R.id.menu_upload:
	    		i.setClass(this, MultiPhotoSelectActivity.class);
	    		startActivity(i);
	            return true;
	        case R.id.menu_portal:
	        	Intent portalIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.wirhassenalledenjul.de/portal.php"));
	        	startActivity(portalIntent);
	            return true;
	        default:
	            return super.onOptionsItemSelected(item);
	    }
	}
	
	@Override
	public void onBackPressed() {
		Intent i = new Intent();
		i.setAction(Intent.ACTION_MAIN);
		i.addCategory(Intent.CATEGORY_HOME);
		this.startActivity(i); 
	}
    
    // Settings button was pressed
    public void settings(View v) {
		Intent i = new Intent();
		i.setClass(this, SettingsActivity.class);
		startActivity(i);
    }

	
}
